<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <script src="/libs/react.development.js"></script>
    <script src="/libs/react-dom.development.js"></script>
    <script src="/libs/babel.min.js"></script>
    <title>Document</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="text/babel">
      class Demo extends React.Component {
        state = {
          opacity: 1,
        };
        death = () => {
          ReactDOM.unmountComponentAtNode(document.getElementById("root"));
        };
        render() {
          return (
            <div>
              <h1 style={{ opacity: this.state.opacity }}>React</h1>
              <button onClick={this.death}>death</button>
            </div>
          );
        }
        componentDidMount() {
          this.timer = setInterval(() => {
            let { opacity } = this.state;
            opacity -= 0.1;
            if (opacity <= 0) opacity = 1;
            this.setState({ opacity });
          }, 200);
        }
        componentWillUnmount() {
          clearInterval(this.timer);
        }
      }
      ReactDOM.render(<Demo />, document.getElementById("root"));
    </script>
  </body>
</html>
